package config

import "time"

// 服务地址和端口
type Server struct {
	Mode         string        `mapstructure:"Mode"`
	Addr         string        `mapstructure:"Addr"`
	Port         string        `mapstructure:"Port"`
	ReadTimeout  time.Duration `mapstructure:"ReadTimeout"`
	WriteTimeout time.Duration `mapstructure:"WriteTimeout"`
	Ssl          bool          `mapstructure:"Ssl"`
	SslDomain    string        `mapstructure:"SslDomain"`
	CertFile     string        `mapstructure:"CertFile"`
	KeyFile      string        `mapstructure:"KeyFile"`
}

// 日志配置
type Logger struct {
	//Open       bool   `mapstructure:"Open"`
	FilePath   string `mapstructure:"FilePath"`
	MaxSize    int    `mapstructure:"MaxSize"`
	MaxBackups int    `mapstructure:"MaxBackups"`
	MaxAge     int    `mapstructure:"MaxAge"`
	Compress   bool   `mapstructure:"Compress"`
}

// 数据库
type Mysql struct {
	Prefix string `mapstructure:"Prefix"`
	Dsn    string `mapstructure:"Dsn"`
}
type Redis struct {
	Addr     string `mapstructure:"Addr"`
	Password string `mapstructure:"Password"`
}
type Database struct {
	Mysql `mapstructure:"Mysql"`
	Redis `mapstructure:"Redis"`
}

type JWT struct {
	AppKey    string        `mapstructure:"AppKey"`
	Secret    string        `mapstructure:"Secret"`
	Issuer    string        `mapstructure:"Issuer"`
	ExpiresAt time.Duration `mapstructure:"ExpiresAt"`
}

type App struct {
	AppName string
	Version string
	//Limit                 int           `mapstructure:"Limit"`
	//IsDel                 bool          `mapstructure:"IsDel"`
	//UploadSavePath        string        `mapstructure:"UploadSavePath"`
	//UploadServerUrl       string        `mapstructure:"UploadServerUrl"`
	//UploadImageMaxSize    int           `mapstructure:"UploadImageMaxSize"`
	//UploadImageAllowExts  []string      `mapstructure:"UploadImageAllowExts"`
	//UploadFileMaxSize     int           `mapstructure:"UploadFileMaxSize"`
	//UploadFileAllowExts   []string      `mapstructure:"UploadFileAllowExts"`
	DefaultContextTimeout time.Duration `mapstructure:"DefaultContextTimeout"`
	//CryptKey              string        `mapstructure:"CryptKey"`
	//InfoValidTime         int           `mapstructure:"InfoValidTime"`
	//QrCryptLength         int           `mapstructure:"QrCryptLength"`
}

type Tracer struct {
	AgentHostPort string `mapstructure:"AgentHostPort"`
}

type Configs struct {
	Server   `mapstructure:"Server"`
	Logger   `mapstructure:"Logger"`
	Database `mapstructure:"Database"`
	App      `mapstructure:"App"`
	Tracer   `mapstructure:"Tracer"`
}

func (c *Configs) SetDefaults() {
	c.App.AppName = AppName
	c.App.Version = Version
}
